package com.lzc.jobrecomendbackend.controller.skills;

import com.lzc.jobrecomendbackend.common.Result;
import com.lzc.jobrecomendbackend.model.skills.SkillCombinationVO;
import com.lzc.jobrecomendbackend.model.skills.SkillDistributionVO;
import com.lzc.jobrecomendbackend.model.skills.SkillQueryRequest;
import com.lzc.jobrecomendbackend.service.skills.SkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/skills")
public class SkillController {

    @Autowired
    private SkillService skillService;

    /**
     * 获取技能需求分布 (GET方式)
     *
     * @param city 城市
     * @param education 学历要求
     * @param experience 经验要求
     * @param page 页码
     * @param size 每页大小
     * @return 技能分布数据
     */
    @GetMapping("/distribution")
    public Result<SkillDistributionVO> getSkillDistribution(
            @RequestParam(required = false) String city,
            @RequestParam(required = false) String education,
            @RequestParam(required = false) String experience,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        try {
            SkillDistributionVO distribution = skillService.getSkillDistribution(
                    city, education, experience, page, size);
            return Result.success(distribution);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
    
    /**
     * 获取技能需求分布 (POST方式)
     *
     * @param request 包含查询条件和分页参数的请求
     * @return 技能分布数据
     */
    @PostMapping("/distribution")
    public Result<SkillDistributionVO> getSkillDistributionPost(@RequestBody SkillQueryRequest request) {
        try {
            // 从请求体中获取页码和每页大小
            int page = request.getPage() != null ? request.getPage() : 1;
            int size = request.getSize() != null ? request.getSize() : 10;
            
            SkillDistributionVO distribution = skillService.getSkillDistribution(
                    request.getCity(), request.getEducation(), request.getExperience(), page, size);
            return Result.success(distribution);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    /**
     * 获取技能组合分析 (GET方式)
     *
     * @param city 城市
     * @param experience 经验要求
     * @param page 页码
     * @param size 每页大小
     * @return 技能组合数据
     */
    @GetMapping("/combinations")
    public Result<SkillCombinationVO> getSkillCombinations(
            @RequestParam(required = false) String city,
            @RequestParam(required = false) String experience,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        try {
            SkillCombinationVO combinations = skillService.getSkillCombinations(
                    city, experience, page, size);
            return Result.success(combinations);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
    
    /**
     * 获取技能组合分析 (POST方式)
     *
     * @param request 包含查询条件和分页参数的请求
     * @return 技能组合数据
     */
    @PostMapping("/combinations")
    public Result<SkillCombinationVO> getSkillCombinationsPost(@RequestBody SkillQueryRequest request) {
        try {
            // 从请求体中获取页码和每页大小
            int page = request.getPage() != null ? request.getPage() : 1;
            int size = request.getSize() != null ? request.getSize() : 10;
            
            SkillCombinationVO combinations = skillService.getSkillCombinations(
                    request.getCity(), request.getExperience(), page, size);
            return Result.success(combinations);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
} 